php 第一次进行 elasticsearch安装

您所在的位置:网站首页 es bootstrap checks failed php 第一次进行 elasticsearch安装

php 第一次进行 elasticsearch安装

2023-07-24 17:04| 来源: 网络整理| 查看: 265

对phper来说,接触java相关的配置都需要好好记录下来。

因为项目需求,现在要自己搭建es环境

java环境请先自行安装,这里主要讲es安装

安装前,es首页默认时最新版,比如我现在默认最新是8.0.0 。

重要!重要!重要!请先根据自己操作系统选择支持的版本 :【链接:】 支持矩阵 | Elastic

一、根据自己的服务器操作系统下载对应安装包

选择版本:【链接:】Elasticsearch Guide | Elastic

进入下载页:

这里有每一种操作系统的完整安装引导

8.0的linux链接:Install Elasticsearch from archive on Linux or MacOS | Elasticsearch Guide [8.0] | Elastic

二、按照文档进行安装elasticSearch

这里分两种形式安装,一种是tar.gz包安装,一种是rpm安装

(一)rpm安装

1.按照官方的命令安装es

执行命令: wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.1-x86_64.rpm wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.1-x86_64.rpm.sha512 yum install perl-Digest-SHA shasum -a 512 -c elasticsearch-7.17.1-x86_64.rpm.sha512 sudo rpm --install elasticsearch-7.17.1-x86_64.rpm 复制代码

[root@localhost opt]# shasum -a 512 -c elasticsearch-7.17.1-x86_64.rpm.sha512 elasticsearch-7.17.1-x86_64.rpm: OK [root@localhost opt]# sudo rpm --install elasticsearch-7.17.1-x86_64.rpm 警告:elasticsearch-7.17.1-x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID d88e42b4: NOKEY Creating elasticsearch group... OK Creating elasticsearch user... OK ### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service ### You can start elasticsearch service by executing sudo systemctl start elasticsearch.service Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore 复制代码

2.修改配置文件 /etc/elasticsearch/elasticsearch.yml

[root@localhost opt]# vim /etc/elasticsearch/elasticsearch.yml [root@localhost opt]# grep -Ev "^#" /etc/elasticsearch/elasticsearch.yml cluster.name: forpastime node.name: node-249 path.data: /data/elasticsearch path.logs: /data/log/elasticsearch bootstrap.memory_lock: true network.host: 192.168.2.249 http.port: 9200 discovery.seed_hosts: ["192.168.2.249"] cluster.initial_master_nodes: ["node-249"] 复制代码

查看修配置文件生效的命令:grep -Ev "^#" /etc/elasticsearch/elasticsearch.yml

3.因为我们指定了es数据和日志存储目录,所以添加目录

[root@localhost /]# mkdir data [root@localhost /]# mkdir data/log [root@localhost /]# mkdir data/elasticsearch [root@localhost /]# mkdir data/log/elasticsearch 复制代码

4.安装后默认添加了elasticsearch用户,所以将新增的目录权限给elasticsearch

[root@localhost /]# chown -R elasticsearch:elasticsearch /data/elasticsearch [root@localhost /]# chown -R elasticsearch:elasticsearch /data/log/elasticsearch 复制代码

5.修改/etc/elasticsearch/jvm.options文件

[root@localhost log]# vim /etc/elasticsearch/jvm.options 增加如下代码 -Xms512m -Xmx512m 复制代码

如果此时启动es,会无法成功,查看日志:

tail -n 1000 /data/log/elasticsearch/elasticsearch.log 或其他日志文件 复制代码

遇到memory is not locked,需要作如下6的操作:

6.执行systemctl edit elasticsearch,输入以下内容

[root@localhost log]# systemctl edit elasticsearch 输入: [Service] LimitMEMLOCK=infinity 复制代码

Ctrl + O提示是否写入,Enter回车 

Ctrl + X 

7.启动es,查看启动状态和端口情况

[root@localhost log]# systemctl daemon-reload [root@localhost log]# systemctl start elasticsearch.service [root@localhost log]# systemctl status elasticsearch ● elasticsearch.service - Elasticsearch Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled) Drop-In: /etc/systemd/system/elasticsearch.service.d └─override.conf Active: active (running) since 三 2022-03-02 11:09:27 CST; 12s ago Docs: https://www.elastic.co Main PID: 19592 (java) Tasks: 69 CGroup: /system.slice/elasticsearch.service ├─19592 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 └─19796 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller 3月 02 11:09:18 localhost.localdomain systemd[1]: Starting Elasticsearch... 3月 02 11:09:27 localhost.localdomain systemd[1]: Started Elasticsearch. [root@localhost log]# ss -lntup|grep 9200 tcp LISTEN 0 128 [::ffff:192.168.2.249]:9200 [::]:* users:(("java",pid=19592,fd=295)) 复制代码

开机自启:systemctl enable elasticsearch.service

rmp安装常见问题:

一般情况9200端口应该是禁用的,所以开放一下9200端口

[root@localhost log]# vim /etc/sysconfig/iptables 追加: -A INPUT -m state --state NEW -m tcp -p tcp --dport 9200 -j ACCEPT 重启防火墙[root@localhost log]# systemctl restart iptables.service 复制代码

注意:服务器重启后重启服务可能要重启防火墙配置,否则9200还是没法访问

systemctl restart iptables.service 复制代码

生产环境配置遇到问题及日志打印问题:

解决办法:

服务器安全组开启9200端口,elasticsearch.yml配置文件内的参数network.host配置为内网ip或0.0.0.0

8.如果是谷歌或者Edge浏览器,可以安装elasticsearch扩展,这里就可以看到安装启动成功信息。

(二)tar包安装 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.0.0-linux-x86_64.tar.gz wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.0.0-linux-x86_64.tar.gz.sha512 shasum -a 512 -c elasticsearch-8.0.0-linux-x86_64.tar.gz.sha512 复制代码

如果没有安装 shasum 无法执行第三条命令,需要安装一下perl-Digest-SHA,linux执行以下命令

yum install perl-Digest-SHA 复制代码

接着执行命令

tar -xzf elasticsearch-8.0.0-linux-x86_64.tar.gz cd elasticsearch-8.0.0/ ##以下是运行elasticSearch命令 ./bin/elasticsearch 复制代码

第一次执行./bin/elasticsearch会报错,原因是不能以root运行

新增用户或者修改为其他用户,并将目录修改为对应用户权限

再次执行启动es命令

./bin/elasticsearch 复制代码

查看打印日志发现:

下图中的参数很重要:!!!!

复制出来

━ ✅ Elasticsearch security features have been automatically configured! ✅ Authentication is enabled and cluster connections are encrypted. ℹ️ Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`): 7FB6Cmd0_GTxJ=_Sa5JD ℹ️ HTTP CA certificate SHA-256 fingerprint: aa1fc51876c2605769cd8d87b1f7391e27cf7b9117369a52a375f7b5e90278ca ℹ️ Configure Kibana to use this cluster: • Run Kibana and click the configuration link in the terminal when Kibana starts. • Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes): eyJ2ZXIiOiI4LjAuMCIsImFkciI6WyIxOTIuMTY4LjIuMjUxOjkyMDAiXSwiZmdyIjoiYWExZmM1MTg3NmMyNjA1NzY5Y2Q4ZDg3YjFmNzM5MWUyN2NmN2I5MTE3MzY5YTUyYTM3NWY3YjVlOTAyNzhjYSIsImtleSI6InlNcHlMMzhCMHVybmw5V1htV3c4OlNCUThvczJZVEFlUE91MzlFRkFHcVEifQ== ℹ️ Configure other nodes to join this cluster: • On this node: ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`. ⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml. ⁃ Restart Elasticsearch. • On other nodes: ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token `, using the enrollment token that you generated. 复制代码 启动elasticsearch遇到的问题

1.修改config/elasticsearch.yml后出现如下问题

ERROR: [2] bootstrap checks failed. You must address the points described in the following [2] lines before starting Elasticsearch. bootstrap check failure [1] of [2]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] bootstrap check failure [2] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] ERROR: Elasticsearch did not exit normally - check the logs at /opt/elasticsearch-8.0.0/logs/elasticsearch.log 复制代码

解决办法:

sudo su -  #查看软限制 #查看硬限制ulimit -H -n ulimit -S -n 复制代码

ulimit -S -n默认软限制1024,硬限制默认4096,修改**/etc/security/limits.conf**

vim /etc/security/limits.conf 复制代码

文件末追加:

* soft nofile 65535* hard nofile 65537 复制代码

退出用户登陆重新登陆

2.启动出现如下问题

ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch. bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] ERROR: Elasticsearch did not exit normally - check the logs at /opt/elasticsearch-8.0.0/logs/my-application.log 复制代码

解决办法

vim /etc/sysctl.conf #文件末追加下面代码 vm.max_map_count = 262145 #执行 sysctl -p 复制代码

三、安装kibana

官网地址:Download Kibana Free | Get Started Now | Elastic

(一)rpm安装

【地址:】Install Kibana with RPM | Kibana Guide [7.17] | Elastic

wget https://artifacts.elastic.co/downloads/kibana/kibana-7.17.1-x86_64.rpm shasum -a 512 kibana-7.17.1-x86_64.rpm sudo rpm --install kibana-7.17.1-x86_64.rpm 复制代码

注意同样需要把5601端口防火墙配置允许访问

1.修改配置文件:

[root@localhost elasticsearch]# vim /etc/kibana/kibana.yml 复制代码

去掉多行配置前面的‘#’,然后执行 grep -Ev "^#" /etc/kibana/kibana.yml

[root@localhost elasticsearch]# grep -Ev "^#" /etc/kibana/kibana.yml server.port: 5601 server.host: "192.168.2.249" server.name: "forpastime-kibana" elasticsearch.hosts: ["http://192.168.2.249:9200"] kibana.index: ".kibana" kibana.defaultAppId: "home" 复制代码

2.启动kibana

[root@localhost elasticsearch]# sudo -i service kibana start 复制代码

**关闭kibana命令:

[root@localhost elasticsearch]# sudo -i service kibana stop 复制代码

3.查看5601端口

[root@localhost elasticsearch]# lsof -i:5601 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME node 6298 kibana 51u IPv4 87238 0t0 TCP localhost.localdomain:esmagent (LISTEN) 复制代码 (二)tar.gz安装

获取到地址后下载到服务器解压,修改config/kibana.yml 进行配置

(三)访问kibana控制台

使用devtool

之后即可使用这个工具配合php进行文档和索引增删改查。

遇到的问题及解决方法

1.这里注意我的上面配置文件格式有问题会报以下错误,因为yml文件冒号后面需要有空格

**can not read a block mapping entry; a multiline key may not be an implicit key **

2.elasticsearch.hosts: ["http://192.168.2.251:9200"\]我写成了

elasticsearch.host: ["http://192.168.2.251:9200"\] 就报错了

3.修改es相关配置时报

“ERROR: Failed to determine the health of the cluster.” 复制代码

解决办法:先启动es服务

4.生产环境启动kibana后无法5601端口无法访问

修改配置文件项,或者最好的是设置为你需要登陆控制台的公网ip比较保险

server.host: 0.0.0.0 复制代码

5. 生产环境 Kibana server is not ready yet

elasticsearch.hosts: ["http://内网IP:9200"] 复制代码

6.生产环境 No alive nodes found in your cluster

$hosts = explode(',',Env::get('elastic.hosts')); $loger = new Logger('es_log'); $logPath = ROOT.'es_log.log'; if(!file_exists($logPath)){ fopen($logPath,'a+'); } $loger->pushHandler(new StreamHandler($logPath)); $serializer = '\Elasticsearch\Serializers\SmartSerializer'; $this->client = ClientBuilder::create() // 实例化 ClientBuilder ->setLogger($loger) //日志 ->setSerializer($serializer) //序列化 ->setHosts($hosts) // 设置主机信息 ->build(); // 构建客户端对象 复制代码

->setHosts(hosts)我这里hosts) 我这里hosts)我这里hosts使用了环境配置文件,配置文件内的ip+端口没有改为生成环境

7.开发测试环境192.168.2.249:5601无法访问。检查是否启动kibana,关闭防火墙

[root@localhost ~]# lsof -i:5601 [root@localhost ~]# systemctl start kibana [root@localhost ~]# systemctl status kibana ● kibana.service - Kibana Loaded: loaded (/etc/systemd/system/kibana.service; disabled; vendor preset: disabled) Active: active (running) since 一 2022-08-15 16:10:43 CST; 34s ago Docs: https://www.elastic.co Main PID: 9852 (node) Tasks: 11 CGroup: /system.slice/kibana.service └─9852 /usr/share/kibana/bin/../node/bin/node /usr/share/kibana/bin/../src/cli/dist --logging.dest="/var/log/kibana/kibana.log" --pid.file="/run/kibana/kibana.pid" --deprecation.skip_deprecate... 8月 15 16:10:43 localhost.localdomain systemd[1]: Started Kibana. [root@localhost ~]# lsof -i:5601 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME node 9852 kibana 51u IPv4 609714 0t0 TCP localhost.localdomain:esmagent (LISTEN) [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead) since 一 2022-08-15 16:12:00 CST; 8s ago Docs: man:firewalld(1) Process: 1013 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS) Main PID: 1013 (code=exited, status=0/SUCCESS) 8月 11 15:57:57 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon... 8月 11 15:58:00 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon. 8月 11 15:58:00 localhost.localdomain firewalld[1013]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Ple...ling it now. 8月 15 16:12:00 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon... 8月 15 16:12:00 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon. Hint: Some lines were ellipsized, use -l to show in full. 复制代码


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3